package com.base.cn.platform.os.controller.op.affiche;

import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.manage.op.affiche.OpReceiveAfficheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 消息接口
 *
 * @author s.li
 * @create 2018-08-30-15:10
 */
@RestController
@RequestMapping("/api/op")
public class ApiAfficheController extends ApiBaseController {

    @Autowired
    private OpReceiveAfficheService receiveAfficheService;

    /**
     * 查询用户消息列表
     * @param userId 用户ID
     * @param currentPage 页码
     * @return Map<String,Object>
     */
    @RequestMapping("/queryUserAfficheList")
    public Map<String,Object> queryUserAfficheList(@RequestParam("userId")BigDecimal userId,
                                                   @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage){
        Map<String, Object> receiveAffiche = new HashMap<>();
        receiveAffiche.put("userId", userId);
        receiveAffiche.put("order", 2);
        Map<String, Object> afficheMap = receiveAfficheService.queryAjaxReceiveAfficheList(currentPage, receiveAffiche, false, false, true);
        return ResultUtil.SUCCESS(afficheMap);
    }

    /**
     * 删除消息
     * @param id 消息ID
     * @return Map<String,Object>
     */
    @RequestMapping("/deleteReceive")
    public Map<String,Object> deleteReceive(@RequestParam("id") String id,@RequestParam(value = "userId",required = false,defaultValue = "0") BigDecimal userId){
        return receiveAfficheService.deleteReceiveAfficheIds(id,userId);
    }

    /**
     * 消息公告修改状态
     * @param id 消息ID
     * @return Map<String,Object>
     */
    @RequestMapping("/updateReceiveStatus")
    public Map<String,Object> updateReceiveStatus(@RequestParam("id") BigDecimal id,@RequestParam(value = "userId",required = false,defaultValue = "0") BigDecimal userId){
        return receiveAfficheService.updateReceiveAfficheById(id,userId);
    }


    /**
     * 获取未读消息数量
     *
     * @param userId
     * @return
     */
    @RequestMapping("/countReceiveAffiche")
    public Map<String,Object> countReceiveAffiche(@RequestParam(value = "userId") BigDecimal userId) {
        return receiveAfficheService.countReceiveAffiche(userId);
    }

}
